package SunDayCoding.TestCode;

import java.util.Random;
import java.util.Scanner;

public class TestRandom {
    public static void main(String[] args) {
        //实例化随机对象
        Random random = new Random();
        int guessNum = random.nextInt(10) + 1;//0--2
        int flag = 0;
//        System.out.println("guessNum = " + guessNum);
        while (true) {
            System.out.println("请输入你猜的数字？1-10");
            Scanner scanner = new Scanner(System.in);
            int userNum = scanner.nextInt();
            if (guessNum > userNum) {
                System.out.println("猜小啦");
                flag++;
            } else if (guessNum < userNum) {
                System.out.println("猜大啦");
                flag++;
            } else if (guessNum == userNum) {
                System.out.println("恭喜你，猜对啦");
                break;
            }
            if (flag < 3) {
                System.out.println("您还剩" + (3 - flag) + "次");
            } else {
                System.out.println("你的次数用完啦！");
                break;
            }
        }

        {
            int x=10; //块级作用域
        }


//        System.out.println("anInt = " + anInt);
    }
}
